package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ChatService;
import com.atguigu.spzx.manager.service.HomeService;
import com.atguigu.spzx.model.dto.chat.MessageDto;
import com.atguigu.spzx.model.vo.chat.chatmessageVo;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.atguigu.spzx.model.vo.chat.contactsVo;
import com.atguigu.spzx.model.vo.chat.chatmessageVo;
import java.util.List;
import java.util.Map;
import com.atguigu.spzx.model.dto.chat.idInformationDto;

@RestController
@RequestMapping(value = "/chat")
public class ChatController {

    @Autowired
    private ChatService chatService;


    @GetMapping("/getallcontacts")
    public Result<contactsVo> GetAllContacts(){
        List<contactsVo> list = chatService.GetAllContacts();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @DeleteMapping("/deletecontacts/{userRId}")
    public Result DeleteContacts(@PathVariable Long userRId){
        chatService.DeleteContacts(userRId);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/savemessage")
    public Result SaveMessage(@RequestBody MessageDto messageDto){
        chatService.SaveMessage(messageDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //获取聊天记录
    @PostMapping("/getoldmessage")
    public Result<chatmessageVo> GetOldMessage(@RequestBody idInformationDto idInformationDto){
        List<Map<String, String>> messagemaplist = chatService.GetOldMessage(idInformationDto);
        return Result.build(messagemaplist,ResultCodeEnum.SUCCESS);
    }

}
